﻿using Ninject;
using NUnit.Framework;

namespace Nx.Clients.Tests
{
    public class WhenUsingTheWebApiClient : TestFixtureBase
    {
        [Test]
        public void ShouldCreateAndDisposeTheClient()
        {
            using (ITestWebApiClient client = Kernel.Get<ITestWebApiClient>())
            {
                Assert.NotNull(client);
            }
        }

        [Test]
        public async void ShouldExecuteGetOnTheClient()
        {
            using (ITestWebApiClient client = Kernel.Get<ITestWebApiClient>())
            {
                Assert.NotNull(client);

                var result = await client.ExecuteGet();

                Assert.NotNull(result);
            }
        }

        [Test]
        public async void ShouldExecuteGetByIdOnTheClient()
        {
            using (ITestWebApiClient client = Kernel.Get<ITestWebApiClient>())
            {
                Assert.NotNull(client);

                string id = "abc";
                var result = await client.ExecuteGetById(id);

                Assert.AreEqual(id, result);
            }
        }

        [Test]
        public async void ShouldExecutePostOnTheClient()
        {
            using (ITestWebApiClient client = Kernel.Get<ITestWebApiClient>())
            {
                Assert.IsNotNull(client);

                Assert.IsTrue(await client.TryPostAsync("abc"));
            }
        }
    }
}
